package com.minghe.client



import com.xue.StockProto
import com.xue.StockServiceGrpc
import io.grpc.Status
import io.grpc.StatusRuntimeException
import io.quarkus.grpc.GrpcClient
import jakarta.ws.rs.GET
import jakarta.ws.rs.Path
import jakarta.ws.rs.Produces
import jakarta.ws.rs.QueryParam
import jakarta.ws.rs.core.MediaType
import jakarta.ws.rs.core.Response

import org.jetbrains.annotations.Blocking


@Path("/api")
class ExampleResource {

     @GrpcClient("stock")
     lateinit var  stockstub : StockServiceGrpc.StockServiceBlockingStub

    @GET
    @Path("/stock")
    @Produces(MediaType.APPLICATION_JSON)
   // @Blocking
    fun stock(
        @QueryParam("storeCode") storeCode: Int,
        @QueryParam("productCode") productCode: String,
        @QueryParam("stockDate")  stockdatestr: String
    ) : Response {
        val request = StockProto.StockRequest.newBuilder()
            .setStoreCode(storeCode)
            .setProductCode(productCode)
            .setStockTime(stockdatestr)
            .build()

        val result = stockstub.getStock(request)
        return Response.ok(result).build()

    }


}

